package jjn.round1;

/**
 * @author Jjn
 * @since 2022/10/23 18:32
 */
public class LeetCode1768_MergeStringsAlternately {
    public String mergeAlternately(String word1, String word2) {
        if (word1 == null) {
            return word2;
        }
        if (word2 == null) {
            return word1;
        }
        int first = word1.length();
        int second = word2.length();
        int max = Math.min(first, second);
        StringBuilder stringBuilder = new StringBuilder();
        for (int i = 0; i < max; i++) {
            stringBuilder.append(word1.charAt(i));
            stringBuilder.append(word2.charAt(i));
        }
        if (max < first) {
            for (int i = max; i < first; i++) {
                stringBuilder.append(word1.charAt(i));
            }
        }
        if (max < second) {
            for (int i = max; i < second; i++) {
                stringBuilder.append(word2.charAt(i));
            }
        }
        return stringBuilder.toString();
    }
}
